<template>
  <div class="tab-box">
    <div v-for="item in tabList" :class="active===item.code?'active':''" @click="changeTab(item)" :key="item.code">{{item.name}}</div>
  </div>
</template>

<script lang="ts">
import { defineComponent, ref } from 'vue'

export default defineComponent({
  name: 'tab',
  props: {
    tabList: [Array],
    defaultActive: ''
  },
  emits: ['changeTab'],
  setup (props, context) {
    const { tabList, defaultActive } = props
    let active = ref(defaultActive || tabList[0].code)
    const changeTab = (data) => {
      active.value = data.code
      context.emit('changeTab',  data.code)
    }
    return { tabList, active, changeTab }
  }
})

</script>

<style scoped lang="less">
  .tab-box {
    margin-left: 36px;
    display: flex;
    background: url("https://web.czb365.com/ty/czb-mosi-wms-web/line-bg.png") repeat-x bottom;
    > div {
      color: #222222;
      font-size: 20px;
      padding-bottom: 14px;
      border-bottom: 4px solid transparent;
      margin-right: 67px;
      text-align: center;
      cursor: pointer;
    }
    .active {
      border-color: #4B7EFE;
      color: #4B7EFE;
    }
  }
</style>
